// Common utils for the extension system and the extension
// preferences tool
+const { Gio, GLib } = imports.gi;
+
const Gettext = imports.gettext;
+const Lang = imports.lang;
const Signals = imports.signals;
-const Gio = imports.gi.Gio;
-
const Config = imports.misc.config;
const FileUtils = imports.misc.fileUtils;
UNINSTALLED: 99
};
+const SERIALIZED_PROPERTIES = ['type', 'state', 'path', 'error', 'hasPrefs'];
+
// Maps uuid -> metadata object
var extensions = {};
return extension;
}
+function serializeExtension(extension) {
+ let obj = {};
+ Lang.copyProperties(extension.metadata, obj);
+
+ SERIALIZED_PROPERTIES.forEach(prop => {
+ obj[prop] = extension[prop];
+ });
+
+ let res = {};
+ for (let key in obj) {
+ let val = obj[key];
+ let type;
+ switch (typeof val) {
+ case 'string':
+ type = 's';
+ break;
+ case 'number':
+ type = 'd';
+ break;
+ case 'boolean':
+ type = 'b';
+ break;
+ default:
+ continue;
+ }
+ res[key] = GLib.Variant.new(type, val);
+ }
+
+ return res;
+}
+
+function deserializeExtension(variant) {
+ let res = { metadata: {} };
+ for (let prop in variant) {
+ let val = variant[prop].unpack();
+ if (SERIALIZED_PROPERTIES.includes(prop))
+ res[prop] = val;
+ else
+ res.metadata[prop] = val;
+ }
+ // add the 2 additional properties to create a valid extension object, as createExtensionObject()
+ res.uuid = res.metadata.uuid;
+ res.dir = Gio.File.new_for_path(res.path);
+ return res;
+}
+
function installImporter(extension) {
let oldSearchPath = imports.searchPath.slice(); // make a copy
imports.searchPath = [extension.dir.get_parent().get_path()];
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const { Gio, GLib, Meta, Shell } = imports.gi;
-const Lang = imports.lang;
const Config = imports.misc.config;
const ExtensionDownloader = imports.ui.extensionDownloader;
}
GetExtensionInfo(uuid) {
- let extension = ExtensionUtils.extensions[uuid];
- if (!extension)
- return {};
-
- let obj = {};
- Lang.copyProperties(extension.metadata, obj);
-
- // Only serialize the properties that we actually need.
- const serializedProperties = ["type", "state", "path", "error", "hasPrefs"];
-
- serializedProperties.forEach(prop => {
- obj[prop] = extension[prop];
- });
-
- let out = {};
- for (let key in obj) {
- let val = obj[key];
- let type;
- switch (typeof val) {
- case 'string':
- type = 's';
- break;
- case 'number':
- type = 'd';
- break;
- case 'boolean':
- type = 'b';
- break;
- default:
- continue;
- }
- out[key] = GLib.Variant.new(type, val);
- }
-
- return out;
+ let extension = ExtensionUtils.extensions[uuid] || {};
+ return ExtensionUtils.serializeExtension(extension);
}
GetExtensionErrors(uuid) {